package edu.corn.job.core.statemachine;

import edu.corn.job.core.context.JobRunningContext;
import edu.corn.statemachine.core.context.DefaultStateContext;

public class JobStateUtil {

    public static void pending(JobRunningContext context) {
        // 将所有锁都释放。
        context.getJobEngine().getStatemachine().sendEvent(JobStateEnum.RUNNING, new DefaultStateContext<>(JobStateEnum.RUNNING, JobStateEnum.PENDING, JobEventEnum.PENDING, context));
    }

    /**
     * 将jobContext放入waiting队列中。等待被执行。
     * @param context
     */
    public static void submit(JobRunningContext context) {
        context.getJobEngine().getStatemachine().sendEvent(JobStateEnum.NEW, new DefaultStateContext<>(JobStateEnum.NEW, JobStateEnum.RUNNABLE, JobEventEnum.NEW, context));
    }

    public static void running(JobRunningContext context) {
        context.getJobEngine().getStatemachine().sendEvent(JobStateEnum.RUNNABLE, new DefaultStateContext<>(JobStateEnum.RUNNABLE, JobStateEnum.RUNNING, JobEventEnum.SUBMIT, context));
    }

}
